//
//  SISSImportBuyerFillInView.m
//  SISSAPP
//
//  Created by 优房网 on 2017/9/6.
//  Copyright © 2017年 优房网. All rights reserved.
//

#import "SISSImportBuyerFillInView.h"

@interface SISSImportBuyerFillInView ()

/// topTitleLabel
@property (weak, nonatomic) UILabel *topTitleLabel;
/// bgView
@property (weak, nonatomic) UIView *bgView;

/// titleLabel
@property (weak, nonatomic) UILabel *titleLabel;
/// firstButton
@property (weak, nonatomic) UIButton *firstButton;
/// secondButton
@property (weak, nonatomic) UIButton *secondButton;

@end
@implementation SISSImportBuyerFillInView

- (void)setCheckNum:(NSInteger)checkNum {
    _checkNum = checkNum;
    self.topTitleLabel.hidden = checkNum;
    switch (checkNum) {
        case 0: {
            self.firstButton.selected = NO;
            self.secondButton.selected = NO;
        }
            break;
            
        case 1: {
            self.firstButton.selected = YES;
            self.secondButton.selected = NO;
        }
            break;
            
        case 2: {
            self.firstButton.selected = NO;
            self.secondButton.selected = YES;
        }
            break;
            
        default:
            break;
    }
}

#pragma mark - UI
- (void)initUI {
    [super initUI];
    
    UILabel *topTitleLabel = [[UILabel alloc] init];
    topTitleLabel.text = @"待买方填写";
    topTitleLabel.textColor = MAIN_TEXT_COLOR;
    topTitleLabel.textAlignment = NSTextAlignmentCenter;
    topTitleLabel.font = [UIFont boldSystemFontOfSize:16];
    [self addSubview:topTitleLabel];
    self.topTitleLabel = topTitleLabel;
    
    UIView *bgView = [[UIView alloc] init];
    bgView.backgroundColor = COLOR(0xF1F1F5);
    bgView.layer.cornerRadius = 5;
    bgView.layer.masksToBounds = YES;
    [self addSubview:bgView];
    self.bgView = bgView;
    
    UILabel *titleLabel = [[UILabel alloc] init];
    titleLabel.text = @"四、买方是否已明确告知中介方，买方具有购房资格。";
    titleLabel.textColor = MAIN_TEXT_COLOR;
    titleLabel.numberOfLines = 0;
    titleLabel.font = [UIFont boldSystemFontOfSize:16];
    [self.bgView addSubview:titleLabel];
    self.titleLabel = titleLabel;
    
    UIButton *firstButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [firstButton setImage:[UIImage imageNamed:@"check"] forState:UIControlStateNormal];
    [firstButton setImage:[UIImage imageNamed:@"mainCheckSelected"] forState:UIControlStateSelected];
    [firstButton setTitleColor:SECONDARY_TEXT_COLOR forState:UIControlStateNormal];
    [firstButton setTitle:@"是" forState:UIControlStateNormal];
    firstButton.userInteractionEnabled = NO;
    [self.bgView addSubview:firstButton];
    self.firstButton = firstButton;
    
    UIButton *secondButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [secondButton setImage:[UIImage imageNamed:@"check"] forState:UIControlStateNormal];
    [secondButton setImage:[UIImage imageNamed:@"mainCheckSelected"] forState:UIControlStateSelected];
    [secondButton setTitleColor:SECONDARY_TEXT_COLOR forState:UIControlStateNormal];
    [secondButton setTitle:@"否" forState:UIControlStateNormal];
    secondButton.userInteractionEnabled = NO;
    [self.bgView addSubview:secondButton];
    self.secondButton = secondButton;
    
}

#pragma mark - 约束
- (void)initConstraint {
    [super initConstraint];
    
    CGFloat margin = 8.0;
    WeakSelf
    [self.topTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(weakSelf);
        make.top.equalTo(weakSelf).offset(margin);
    }];
    
    [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf).offset(margin);
        make.top.equalTo(weakSelf.topTitleLabel.mas_bottom).offset(margin);
        make.right.equalTo(weakSelf).offset(-2 * margin);
        make.bottom.equalTo(weakSelf).offset(-margin);
    }];
    
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.equalTo(weakSelf.bgView).offset(margin);
        make.right.equalTo(weakSelf.bgView).offset(-margin);
    }];
    
    [self.firstButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.titleLabel);
        make.top.equalTo(weakSelf.titleLabel.mas_bottom).offset(2 * margin);
    }];
    [self.secondButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.firstButton);
        make.top.equalTo(weakSelf.firstButton.mas_bottom).offset(2 * margin);
        make.bottom.equalTo(weakSelf.bgView).offset(-margin);
    }];
}

@end
